home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / RWSUB2I.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  3KB  |  100 lines

  1. ; RWSUB2I - disk read/write subroutine for interpretive BASIC
  2. ; Copyright 1983 Data Base Decisions
  3. ;
  4. ; Note: This routine requires DOS 2.00 or later!
  5. ;
  6. ; CALL RWSUB2I(STACK$,FIL$,FUNC%,SBYTELO%,SBYTEHI%,NOBYTES%,DTASEG%,RETCODE%)
  7. ; STACK$ is a temporary stack (not needed by compiled version)
  8. ; FIL$ is the file name in ASCIIZ format
  9. ; FUNC% indicates reading (=0), writing (=1), or creating (and writing =2)
  10. ; SBYTELO% is the low part of the starting byte
  11. ; SBYTEHI% is the high part of the starting byte (HI*65536+LO)
  12. ; NOBYTES% is the number of bytes to be read/written
  13. ; DTASEG% is the segment to be read into or written from
  14. ; RETCODE% is an error return code (non-zero if an error occurred)
  15.  
  16. skip    equ 1            ; 2 for compiled, 1 for interpretive
  17.  
  18. cseg    segment para public 'code'
  19. public    rwsub2i
  20. rwsub2i proc far
  21.     assume cs:cseg,ds:nothing,ss:nothing,es:nothing
  22.  
  23.     push bp
  24.     mov bp,sp
  25.  
  26.                 ; use passed stack
  27.     mov di,sp        ; save orig sp
  28.     mov si,[bp+20]        ; point to STACK$
  29.     mov al,[si]        ; get length
  30.     mov ah,0
  31.     add si,skip
  32.     add ax,[si]        ; add start addr
  33.     dec ax            ; down by 1
  34.     mov sp,ax        ; new sp
  35.     push di         ; save orig sp on new stack
  36.  
  37.                 ; open the file
  38.     mov si,[bp+18]        ; point to FIL$
  39.     add si,skip
  40.     mov dx,[si]        ; point to file name
  41.     mov si,[bp+16]        ; point to FUNC%
  42.     mov al,[si]        ; get access code in al
  43.     mov ah,3dh
  44.     cmp al,2        ; create?
  45.     jnz p010        ; no
  46.     dec ah
  47.     mov cx,0        ; clear attributes
  48. p010:    int 21h         ; open the file
  49.     jc p030         ; error?
  50.  
  51.                 ; set the file pointer
  52.     mov bx,ax        ; get the handle
  53.     mov si,[bp+12]        ; point to SBYTEHI%
  54.     mov cx,[si]        ; put it in cx
  55.     mov si,[bp+14]        ; point to SBYTELO%
  56.     mov dx,[si]        ; put it in dx
  57.     mov ah,42h        ; move file read/write pointer
  58.     mov al,0        ; method 0 - offset from beginning of file
  59.     int 21h         ; position in the file
  60.     jc p030         ; error?
  61.  
  62.                 ; read/write the file
  63.     mov si,[bp+10]        ; point to NOBYTES%
  64.     mov cx,[si]        ; number of bytes to read/write
  65.     mov si,[bp+16]        ; point to FUNC%
  66.     mov ah,[si]        ; 0 for read, 1 for write
  67.     cmp ah,2        ; create?
  68.     jnz p020        ; no
  69.     dec ah            ; yes - make it a write
  70. p020:    add ah,3fh        ; setup interrupt function
  71.     push ds
  72.     mov si,[bp+8]        ; point to DTASEG%
  73.     mov dx,[si]
  74.     mov ds,dx        ; now in ds
  75.     xor dx,dx        ; ds:dx contains DTA
  76.     int 21h         ; read/write the file
  77.     pop ds            ; get orig ds
  78.     jc p030         ; error?
  79.     mov si,[bp+10]        ; point to NOBYTES%
  80.     mov [si],ax        ; save bytes read/written
  81.  
  82.                 ; close the file
  83.     mov ah,3eh
  84.     int 21h         ; close the file
  85.     jnc p040        ; no error
  86.  
  87. p030:                ; error handler
  88.     mov si,[bp+6]        ; point to RETCODE%
  89.     mov [si],ax        ; save the error
  90.  
  91. p040:                ; return to caller
  92.     pop di            ; get orig sp
  93.     mov sp,di        ; back to orig stack
  94.     pop bp
  95.     ret 16
  96.  
  97. rwsub2i endp
  98. cseg    ends
  99.     end
  100.